import { picturePreview } from '@/api/maintenance/maintenance'

const picMixins = {
  methods: {
    // 获取图片资源
    async getImage(row, rate) {
      // applyTemplateFileId 备案申请表模板文件
      // businessLicensePicId 营业执照扫描件图片
      // maintainLicensePicId 安装改造维修许可证图片
      // produceLicensePicId 特种设备生产许可证图片

      await picturePreview(row.applyTemplateFileId, rate).then(res => {
        return 'data:image/jpeg;base64,' + btoa(new Uint8Array(res).reduce((data, byte) => data + String.fromCharCode(byte), ''))
      }).then(data => {
        this.applyImage = data
        return this.applyImage
      })
      await picturePreview(row.businessLicensePicId, rate).then(res => {
        return 'data:image/jpeg;base64,' + btoa(new Uint8Array(res).reduce((data, byte) => data + String.fromCharCode(byte), ''))
      }).then(data => {
        this.businImage = data
        return this.businImage
      })
      await picturePreview(row.maintainLicensePicId, rate).then(res => {
        return 'data:image/jpeg;base64,' + btoa(new Uint8Array(res).reduce((data, byte) => data + String.fromCharCode(byte), ''))
      }).then(data => {
        this.maintainImage = data
        return this.maintainImage
      })
      await picturePreview(row.produceLicensePicId, rate).then(res => {
        return 'data:image/jpeg;base64,' + btoa(new Uint8Array(res).reduce((data, byte) => data + String.fromCharCode(byte), ''))
      }).then(data => {
        this.produceImage = data
        return this.produceImage
      })
    }
  }
}

export default picMixins
